package com.education.cms.dao;

import com.education.cms.domain.UserCourse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


public interface UserCourseDao extends JpaRepository<UserCourse,Integer> {

    Integer countByCourseIdAndStatus(int courseId,int status);

    Integer countByUserIdAndStatus(int userId,int status);

    UserCourse findUserCourseByUserIdAndStatus(int userId,int status);
    @Modifying
    @Query("update UserCourse userCourse set userCourse.status = 1 where userCourse.courseId = :courseId")
    void finishClass(@Param("courseId")Integer courseId);
}
